import * as YvanUI from "yvan-ui-wotu"
import CustomDict from '../widget/custom.dict'
import * as CustomService from '@server/example/CustomService'

const React = YvanUI.React
const _ = YvanUI.lodash

interface Ref {
    grid1: YvanUI.Grid
}

export default class GridFilter extends YvanUI.Scope<void, Ref> {

    main = this.$$({
        check1: ''
    })

    onRender() {
        this.watch(()=>this.main.check1,
            (v)=> {
                this.refs.grid1.loading = (v === '1')
            });
    }

    vjson = this.$$({
        view: 'page',
        title: '表头筛选',
        items: [
            {
                view: 'card',
                bodyStyle: {
                    padding: 0
                },
                items: [
                    {
                        view: 'grid',
                        title: '表头筛选',
                        ref: 'grid1',
                        idField: "customerid",
                        toolbar: [
                            {
                                view: 'button',
                                text: '刷新',
                                icon: 'fa fa-refresh',
                                type: 'primary',
                                onClick: () => {
                                    this.refs.grid1.refresh()
                                }
                            },
                        ],
                        columns: [
                            {field: "customerid", hidden: true},
                            {field: "customer_code", filterable: true, title: "客户编号"},
                            {field: "customer_name", filterable: true, title: "客户名称"},
                            {field: "logogram", filterable: true, title: "助记码"},
                            {field: "login_count", title: '登录次数', filterable: true, type: 'number', align: 'right'},
                            {field: "industry_class", title: "客户类型", filterable: true, data: CustomDict.industryclass},
                            {field: "customer_type", title: "客户类别", filterable: true, data: CustomDict.customertype},
                            {field: "accounts", title: '结算方', filterable: true},
                            {field: "shipper", title: '承运方', filterable: true},
                            {field: "zip", title: '邮编', filterable: true},
                            {field: "contact", title: '联系人', filterable: true},
                            {field: "telephone", title: '电话', filterable: true},
                            {
                                field: "is_enable",
                                title: '是否启用',
                                filterable: true,
                                formatter: (v) => (_.trim(v) === '1' ? '启用' : '不启用')
                            },
                            {field: "remark", title: '备注', filterable: true},
                            {field: "create_by", title: '创建者', filterable: true},
                            {field: "create_at", title: '建立时间', filterable: true, type: 'date', formatter: 'fmtDate'},
                            {field: "update_by", title: '修改者', filterable: true},
                            {field: "update_at", title: '更新时间', filterable: true, type: 'date', formatter: 'fmtDate'},
                        ],
                        autoDataSource: true,
                        dataSource: {
                            func: CustomService.selectAll
                        }
                    }
                ]
            }
        ]
    })
}